package com.dimples.dd.system.controller;

import com.dimples.dd.common.constant.DDServerConstant;
import com.dimples.dd.common.pojo.PageResult;
import com.dimples.dd.log.core.annotation.ApiLog;
import com.dimples.dd.log.core.enums.OperateTypeEnum;
import com.dimples.dd.system.api.logger.dto.LoginLogCreateReqDTO;
import com.dimples.dd.system.model.query.LoginLogPageQuery;
import com.dimples.dd.system.model.vo.LoginLogPageVO;
import com.dimples.dd.system.service.SystemLoginLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Tag(name = "10.登录日志")
@RestController
@RequestMapping("/login-log")
@Validated
@RequiredArgsConstructor
public class SysLoginLogController {

    private final SystemLoginLogService loginLogService;

    @GetMapping("/page")
    @Operation(summary = "获得登录日志分页列表")
    @PreAuthorize("@ss.hasPerm('system:login-log:query')")
    @ApiLog(operateType = OperateTypeEnum.SELECT, applicationName = DDServerConstant.DD_SERVER_SYSTEM)
    public PageResult<LoginLogPageVO> selectLoginLogPage(@Valid LoginLogPageQuery pageQuery) {
        return this.loginLogService.selectLoginLogPage(pageQuery);
    }


    @PostMapping
    @Operation(summary = "创建登录日志", hidden = true)
    public void createLoginLog(@Valid @RequestBody LoginLogCreateReqDTO loginLogCreateReqDTO) {
        this.loginLogService.createLoginLog(loginLogCreateReqDTO);
    }

}
